package com.abner.juc.unsafelist;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author Abner
 */
public class CallableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // futureTask实现了runnable接口 所以采用多态的思想
        FutureTask futureTask = new FutureTask(new MyThread());
        new Thread(futureTask,"A").start();
        System.out.println(futureTask.get());
    }
}

/**
 * 与runnable区别
 *      有返回值
 *      抛异常
 *      调用call
 */
class MyThread implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        System.out.println("进来了----");
        return 1024;
    }
}